// ****************************************************************************
//	Copyright (c) 2011 Daniel Watman
//	http://www.keycommander.net/
// ****************************************************************************
//	This program is free software: you can redistribute it and/or modify
//	it under the terms of the GNU General Public License as published by
//	the Free Software Foundation, either version 3 of the License, or
//	(at your option) any later version.
//	
//	This program is distributed in the hope that it will be useful,
//	but WITHOUT ANY WARRANTY; without even the implied warranty of
//	 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//	GNU General Public License for more details.
//	
//	You should have received a copy of the GNU General Public License
//	along with this program.  If not, see <http://www.gnu.org/licenses/>.
// ****************************************************************************
//	File: USB.h
//	Purpose: functions for USB connectivity using MAX3420 USB perhiperal controller
//	Author:	Daniel Watman
//	Created: 2011.02.28
//	Updated: 2011.02.28
//	Version: 0.1
// ****************************************************************************

#include "types.h"

// for SPI
#define ACKSTAT 0x01
#define WRITE	0x02

// MAX3420 registers
#define R0_EP0FIFO		0x00
#define R1_EP1OUTFIFO	0x08
#define R2_EP2INFIFO	0x10
#define R3_EP3INFIFO	0x18
#define R4_SUDFIFO		0x20
#define R5_EP0BC		0x28
#define R6_EP1OUTBC		0x30
#define R7_EP2INBC		0x38
#define R8_EP3INBC		0x40
#define R9_EPSTALLS		0x48
#define R10_CLRTOGS		0x50
#define R11_EPIRQ		0x58
#define R12_EPIEN		0x60
#define R13_USBIRQ		0x68
#define R14_USBIEN		0x70
#define R15_USBCTL		0x78
#define R16_CPUCTL		0x80
#define R17_PINCTL		0x88
#define R18_REVISION	0x90
#define R19_FNADDR		0x98
#define R20_IOPINS		0xA0
#define R_DUMMY			0x98

void USB_setup_data(void);

void USB_setup_get_status(u08, u08);	// get status
void USB_setup_clr_feature(u08, u08, u08);	// clear feature
void USB_setup_set_feature(u08, u08, u08);	// set feature
void USB_setup_set_address(void);	// set address
void USB_setup_get_descriptor(u08, u08, u08, u08);	// send descriptor to host
void USB_setup_get_config(void);	// get configuration
void USB_setup_set_config(u08);	// set configuration
void USB_setup_get_interface(u08);	// get interface
void USB_setup_set_interface(u08, u08);	// set interface
u16 min_u16(u16, u16);

// keyboard bitmasks/codes

// special key bitmasks
#define KB_LCTRL	0x01
#define KB_LSHFT	0x02
#define KB_LALT		0x04
#define KB_LGUI		0x08
#define KB_RCTRL	0x10
#define KB_RSHFT	0x20
#define KB_RALT		0x40
#define KB_RGUI		0x80

// key codes
#define KB_A	0x04
#define KB_B	0x05
#define KB_C	0x06
#define KB_D	0x07
///etc. will fill in if needed
